﻿using System;
using System.Text;
using System.Windows.Forms;
using System.Collections.Generic;

using gKodes.Drawing;
using gKodes.Collections;

namespace gKodes.Windows.Forms
{
    //public abstract class Controller : HexView.Controller
    //{
    //}
}


//private class Controller : ControllerBase
//{
//    private bool IsSelectionOn;

//    private bool MultiSelection;

//    private Range mtSelection;

//    private IHPageSegmentN mfPSegment;

//    protected override void OnDataSourceChanged(object sender, EventArgs e)
//    {
//        bool tr = this.IsRegister;
//        base.OnDataSourceChanged(sender, e);
//        if (sender != null && sender == this.BelogsTo)
//        {
//            if (this.BelogsTo.Source != null)
//            {
//                if (this.IsRegister != tr)
//                {
//                    this.BelogsTo.PreviewKeyDown += new PreviewKeyDownEventHandler(OnKeyDownPreview);
//                    this.BelogsTo.KeyDown += new KeyEventHandler(OnKeyDown);
//                    this.BelogsTo.KeyUp += new KeyEventHandler(OnKeyUp);
//                    this.BelogsTo.KeyPress += new KeyPressEventHandler(OnKeyPress);

//                    this.BelogsTo.MouseDown += new MouseEventHandler(OnMouseDown);
//                    this.BelogsTo.MouseMove += new MouseEventHandler(OnMouseMove);
//                    this.BelogsTo.MouseUp += new MouseEventHandler(OnMouseUp);
//                }
//            }
//            else
//            {
//                this.BelogsTo.PreviewKeyDown -= new PreviewKeyDownEventHandler(OnKeyDownPreview);
//                this.BelogsTo.KeyDown -= new KeyEventHandler(OnKeyDown);
//                this.BelogsTo.KeyUp -= new KeyEventHandler(OnKeyUp);

//                this.BelogsTo.MouseDown -= new MouseEventHandler(OnMouseDown);
//                this.BelogsTo.MouseMove -= new MouseEventHandler(OnMouseMove);
//                this.BelogsTo.MouseUp -= new MouseEventHandler(OnMouseUp);
//            }
//        }
//    }

//    protected override void MoveToOffset(double offset)
//    {
//        //long OldOffset = (long)this.CaretOffset;
//        //long diff = OldOffset - offset;
//        base.MoveToOffset(offset);
//        this.ValidateSelection();
//    }

//    #region Selection method's

//    public void StartSelection()
//    {
//        this.IsSelectionOn = true;
//        this.mtSelection.Start = (long)this.CaretOffset;
//    }

//    public void ValidateSelection()
//    {
//        if (this.IsSelectionOn)
//        {
//            this.RemoveOffsetState(this.mtSelection, 1);
//            this.mtSelection.End = (long)(this.CaretOffset - 1);
//            this.AddOffsetState(this.mtSelection, 1);
//        }
//        else
//        {
//            if (!this.MultiSelection)
//                this.RemoveOffsetState(this.BelogsTo.Source.Range, 1);// new Range(0, 1000)
//        }
//    }

//    public void EndSelection()
//    {
//        this.IsSelectionOn = false;
//        //this.mtSelection.End = (long)this.CaretOffset;
//        //TODO: fire event
//    }

//    #endregion

//    #region Mouse method's

//    private void OnMouseDown(object sender, MouseEventArgs e)
//    {
//        this.CaretManger.Freeze();
//        this.OnMouseMove(sender, e);
//        this.StartSelection();
//    }

//    private void OnMouseMove(object sender, MouseEventArgs e)
//    {
//        if (e.Button == MouseButtons.Left)
//        {
//            IPageSegment psegment = this.GetSegmentOfPixel(e.Location);
//            if (psegment is IHPageSegmentN)
//            {
//                //if (this.mfPSegment != null && this.mfPSegment != psegment)
//                //    this.mfPSegment.Controler.Vertical = true;
//                this.mfPSegment = (IHPageSegmentN)psegment;
//                //this.mfPSegment.Controler.Vertical = false; 
//                this.MoveToOffset(this.AccessibleRange.Start + Helper.ScreenPixelToPoint(this.mfPSegment, e.Location));
//            }
//        }
//    }

//    private void OnMouseUp(object sender, MouseEventArgs e)
//    {
//        this.EndSelection();
//        this.CaretManger.Melt();
//    }

//    #endregion

//    #region Keyboard Events

//    private void OnKeyUp(object sender, KeyEventArgs e)
//    {
//        if (e.KeyCode > Keys.Space && e.KeyCode < Keys.Select)
//            this.CaretManger.Melt();

//        if (IsSelectionOn && !e.Shift)
//        {
//            this.MultiSelection = e.Control;
//            this.EndSelection();
//        }
//        //this.MultiSelection = e.Control;
//    }

//    private void OnKeyDown(object sender, KeyEventArgs e)
//    {
//        if (e.Shift)// && e.KeyCode == (Keys.ShiftKey | Keys.Shift)
//        {
//            this.MultiSelection = e.Control;
//            this.StartSelection();
//        }
//    }

//    private void OnKeyPress(object sender, KeyPressEventArgs e)
//    {
//        if ((mfPSegment.Name.Equals("Hex") && (e.KeyChar > '0' && e.KeyChar < 'G'))
//            || mfPSegment.Name.Equals("Text"))
//        {
//            this.BelogsTo.Source.Write((long)this.CaretOffset, 0,
//                        Convert.ToByte(e.KeyChar));
//            this.AddOffsetState(new Range((long)this.CaretOffset, (long)this.CaretOffset), 2);
//            this.MoveToOffset(this.CaretOffset + mfPSegment.CellProperties.Dividend);
//        }
//    }

//    private void OnKeyDownPreview(object sender, PreviewKeyDownEventArgs e)
//    {
//        if (e.KeyCode > Keys.Space && e.KeyCode < Keys.Select)
//        {

//            double offset = this.CaretOffset;
//            if (!e.Control && (this.CaretOffset % 1 > 0))
//                offset = Math.Floor(offset);
//            this.CaretManger.Freeze();

//            if (e.KeyCode > Keys.Home && e.KeyCode < Keys.Select)
//            {

//                int id = (int)e.KeyCode - 39;//mfPSegment.CellProperties.Dividend
//                float moveby = (Math.Abs(id) != 1) ? ((++id) * ((e.Control && !e.Shift) ? 0.5f : 1f)) :
//                    id * this.BelogsTo.Table.Columns;
//                offset += moveby;
//            }
//            else if (e.KeyCode == Keys.Home)
//                offset = 0;
//            else if (e.KeyCode == Keys.End)
//                offset = this.CaretRange.End;
//            else// if (e.KeyCode > Keys.Space && e.KeyCode < Keys.End)
//            {
//                int mulby = ((e.KeyCode == Keys.PageUp) ? -1 : 1);
//                this.MoveByLine((int)this.BelogsTo.Table.Rows * mulby);
//                offset += ((this.BelogsTo.Table.Size + 1) * mulby);//this.CaretOffset + 
//            }
//            this.MoveToOffset(offset);

//        }
//    }

//    #endregion
//}